package com.itheima.request;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Map;

/**
 * @Author: yg
 * @create 2025-02-04 - 20:56
 * @
 */
@WebServlet("/req2")
public class RequestDemo2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("get...");
        //1.获取所有参数的Map集合
        Map<String, String[]> map = req.getParameterMap();
        for (String key: map.keySet()){
            System.out.print(key + ":");
            String[] values = map.get(key);
            for (String value: values){
                System.out.print(value + " ");
            }
            System.out.println();
        }
        System.out.println("-------------------");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.获取post请求体：请求参数
        //2.获取字符输入流
        BufferedReader bf = req.getReader();
        //3.读取数据
        String line = bf.readLine();
        System.out.println(line);

    }
}
